package org.idea.qiyu.threadpool.demo.sendemail;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 发送邮件服务
 *
 * @Author linhao
 * @Date created in 11:24 上午 2021/10/16
 */
@Service
public class SendEmailServiceImpl implements SendEmailService {

    @Resource
    private ExecutorService emailTaskPool;


    @Override
    public void sendEmail(EmailDTO emailDTO) {
        emailTaskPool.submit(() -> {
            try {
                System.out.printf("sending email .... emailDto is %s \n", emailDTO);
                Thread.sleep(1000);
                System.out.println("sended success");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
    }

}
